package com.gp.controller;


import com.gp.entity.Advertise;
import com.gp.service.AdvertiseService;
import com.gp.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@RestController
@RequestMapping("/marketing/advertise")
public class AdvertiseController {
    @Autowired
    private AdvertiseService advertiseService;
    @GetMapping("/findAll")
    public CommonResult findAll(Integer page, Integer limit, Advertise advertise){

       return advertiseService.findAll(page,limit,advertise);
    }

    @DeleteMapping("/deleteById")
    public CommonResult deleteById(Integer id){
        return advertiseService.deleteById(id);
    }


    @PutMapping("/updateById")
    public CommonResult updateById(Long id, String name, Long positionId, String pic, Date startTime,Date endTime,Integer status,Integer clickCount,Integer orderCount,String url,String note,Integer sort){
        Advertise advertise = new Advertise();
        advertise.setId(id);
        advertise.setName(name);
        advertise.setPositionId(positionId);
        advertise.setPic(pic);
        advertise.setStartTime(startTime);
        advertise.setEndTime(endTime);
        advertise.setStatus(status);
        advertise.setClickCount(clickCount);
        advertise.setOrderCount(orderCount);
        advertise.setUrl(url);
        advertise.setNote(note);
        advertise.setSort(sort);
        return advertiseService.updateById(advertise);
    }


    @PostMapping("/insert")
    public CommonResult insert(Advertise advertise){
        Advertise advertise1 = new Advertise();
        advertise1.setName(advertise.getName());
        advertise1.setPic(advertise.getPic());
        advertise1.setSort(advertise.getSort());
        return advertiseService.insert(advertise);
    }
}
